<?php

$registration_id = $_REQUEST['registration_id'];

if ($_POST['Submit']) {
	em_update_participant();	
}

$registration = $wpdb->get_row("SELECT * from $em_registration_table where id = '$registration_id'");
//echo "SELECT * from $em_registration_table where id = '$registration_id'";

if ($_POST['Submit']) {
	?>
	<div id="message" class="updated fade"><p>
		<strong>Participant saved, <a href="<?php echo EM_URL ?>participant-list.php&amp;event_id=<?php echo $registration->event_id ?>">Return to Participant List &raquo;</a></strong>
	</p></div>
	<?php
}

?>

<div class="wrap">
<script type="text/javascript" src="<?php echo EM_BASE_URL ?>/dateparse.js"></script>
<h2>Edit Participant</h2>
<form name="form1" method="post" action=""> 
<input type="hidden" name="registration_id" value="<?php echo $registration_id ?>"/>
<input type="hidden" name="event_id" value="<?php echo $registration->event_id ?>"/>
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<tr valign="top"> 
	<th width="33%" scope="row"><?php _e('Email Address:') ?></th> 
	<td><input name="email_address" type="text" id="email_address" size="50" value="<?php echo $registration->email_address ?>"/></td> 
</tr>
<tr valign="top"> 
	<th width="33%" scope="row"><?php _e('First Name:') ?></th> 
	<td><input name="first_name" type="text" id="first_name" size="50" value="<?php echo $registration->first_name ?>"/></td> 
</tr>
<tr valign="top"> 
	<th scope="row"><?php _e('Last Name:') ?></th> 
	<td><input name="last_name" type="text" id="last_name" size="50" value="<?php echo $registration->last_name ?>"/></td> 
</tr>
<tr>
	<th scope="row"><?php _e('Address:') ?></th>
	<td><input type="text" name="address1" size="50" maxlength="100" value="<?php echo $registration->address1 ?>"/></td>
</tr>
<tr>
	<td></td>
	<td><input type="text" name="address2" size="50" maxlength="100" value="<?php echo $registration->address2 ?>"/></td>
</tr>
<tr>
	<th scope="row"><?php _e('City:') ?></th>
	<td><input type="text" name="city" size="30" maxlength="64" value="<?php echo $registration->city ?>"/></td>
</tr>
<tr>
	<th scope="row"><?php _e('State:') ?></th>
	<td><input type="text" name="state" size="2" maxlength="2" value="<?php echo $registration->state ?>"/></td>
</tr>
<tr>
	<th scope="row"><?php _e('Zip:') ?></th>
	<td><input type="text" name="zip" size="10" maxlength="10" value="<?php echo $registration->zip ?>"/></td>
</tr>
<tr>
	<th scope="row"><?php _e('Phone:') ?></th>
	<td><input type="text" name="phone" size="15" maxlength="15" value="<?php echo $registration->phone ?>"/></td>
</tr>
<?php
$questions = $wpdb->get_results("SELECT * from `$em_question_table` where event_id = '$registration->event_id' order by sequence");
$answers = $wpdb->get_results("SELECT a.answer from `$em_answer_table` a " 
				. "inner join `$em_question_table` q on a.question_id = q.id " 
				. "where a.registration_id = '$registration->id' " 
				. "order by q.sequence");

if ($questions)
for ($i = 0; $i < count($questions); $i++) {
?>
<tr>
	<th scope="row"><?php echo $questions[$i]->question ?></th>
	<td><?php em_render_form_field($questions[$i], $answers[$i]) ?></td>
</tr>
<?php } ?>
</table>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Edit Participant') ?> &raquo;" />
</p>
</form>
</div>